package com.siebre.picclife.asynctask.model;

import org.joda.time.Duration;
import org.joda.time.Instant;

import com.siebre.bmo.Auditable;

/**
 * 
 * @author ZhangChi
 * @since 2015年4月2日
 */
public interface Task extends Auditable {
	
	long getOid();
	
	String getType();
	
	TaskStatus getStatus();
	
	//XXX consider supporting multiple arguments
	String getArgument();
	
	@Deprecated
	int start();
	
	/**
	 * Start execution of this Task
	 * 
	 * @param processor task executor id used for tracing
	 * @return current execution count
	 */
	int startBy(String processor);
	
	void complete();

	TaskStatus complete(Throwable cause);
	
	TaskStatus completeWithFailure(String message);
	
	void markAsCorrupted();
	
	int getFailureCount();
	
	ProcessStats lastProcessStats();
	
	public static class ProcessStats {
		
		private final String processor;
		
		private final Instant startTime;
		
		private final Duration processDuration;
		
		private final String resultMessage;

		public ProcessStats(String processor, Instant startTime, Duration processDuration, String resultMessage) {
			this.processor = processor;
			this.startTime = startTime;
			this.processDuration = processDuration;
			this.resultMessage = resultMessage;
		}

		public String getProcessor() {
			return processor;
		}

		public Instant getStartTime() {
			return startTime;
		}

		public Duration getProcessDuration() {
			return processDuration;
		}

		public String getResultMessage() {
			return resultMessage;
		}
	}
}
